<?php

namespace App\Module\Sub;

use App\depository\PermissionsDep;
use App\depository\PlayerSecretDep;
use App\depository\RoleHasPermissionsDep;
use App\depository\RolesDep;
use App\depository\SubPermissionsDep;
use App\depository\TeamsDep;
use App\Enum\CommonEnum;
use App\Enum\PermissionsEnum;
use App\Enum\RolesEnum;
use App\Models\ManageSecretModel;
use App\Module\BaseModule;
use App\Service\DictService;
use App\depository\SubRolesDep;
use App\depository\SubRoleHasPermissionsDep;
use App\depository\ManageSecretDep;

class SubPlayerSecretModule extends BaseModule
{

    public function init($request){

        $dictService = new DictService();
        $teamId = $request->headers->get('TeamId');

        $dictService->setSecretGroup($teamId);

        $data['dict'] = $dictService->getDict();

        return self::response($data);

    }

    public function del($request)
    {
        $param = $request->input();

        $dep = new PlayerSecretDep();

        $dep->del($param['id']);

        return self::response();
    }

    public function list($request)
    {
        $param = $request->input();
        $teamId = $request->headers->get('TeamId');

        $dep = new PlayerSecretDep();
        $resList = $dep->list($teamId,$param);
        $list = $resList->getCollection()->toBase();

        $data['list'] = $list->map(function ($item) {
            return [
                'id' => $item->id,
                'steamid' => $item->steamid,
                'start_at' => $item->start_at,
                'end_at' => $item->end_at,
                'group' => $item->group,
                'created_at' => $item->created_at->toDateTimeString()
            ];
        });
        $data['page'] = [
            'per_page' => $param['per_page'],
            'current_page' => $param['current_page'],
            'total_page' => $resList->lastPage(),
            'total' => $resList->total(),
        ];
        return self::response($data);
    }

}

